// import {
//   getCategoryList
// } from '../../../services/good/fetchCategoryList';
import {
  queryMasterList,
  getSwiper,
  getWorklist
} from '../../../api/index'


Page({
  data: {
    list: [],
    imgALL: [],
    masterList: [],
    baseUrl: 'https://oss.peibanmao.com/',
    bgi: [],
    workList: [],
  },

  async init() {
    try {
      const result = await getCategoryList();
      this.setData({
        list: result,
      });
    } catch (error) {
      console.error('err:', error);
    }
  },

  onShow() {
    this.getTabBar().init();
  },
  onChange() {
    wx.navigateTo({
      url: '/pages/goods/list/index',
    });
  },
  onLoad() {
    this.init(true);
  },
  init() {
    this.queryMasterListFn()
    this.getSwiperFn()
    this.getWorklistFn()
  },
  goInfo(e) {
    console.log(e.currentTarget.dataset.item, 'e.currentTarget.dataset.item')
    const id = e.currentTarget.dataset.item.id
    wx.navigateTo({
      url: '/pages/goods/item/index?id=' + id
    });
  },
  queryMasterListFn() {
    queryMasterList({
      pageNum: 1,
      pageSize: 10
    }).then(res => {
      this.setData({
        masterList: res.data.item,
      })
    })
  },
  getSwiperFn() {
    getSwiper({
      id: 25
    }).then((res) => {
      console.log(res.data.item, 'res');
      const urls = res.data.item.map(v => "https://oss.peibanmao.com/" + v.url);
      console.log(urls, 'url')
      this.setData({
        bgi: urls,
      });
    })
  },
  goToInfo(e) {
    const id = e.currentTarget.dataset.item.id
    wx.navigateTo({
      url: '/pages/goods/itemWork/index?id=' + id,
    })
  },
  getWorklistFn() {
    getWorklist({
      pageSize: 10,
      pageNum: 1,
    }).then(res => {
      this.setData({
        workList: res.data.item
      })
      console.log(res, 'res')
    })
  },
  handleContact(e) {
    console.log(e.detail.path, 'e.detail.path')
  },
  //转发给朋友
  onShareAppMessage() {
    const promise = new Promise(resolve => {
      setTimeout(() => {
        resolve({
          title: '时忆旅拍'
        })
      }, 2000)
    })
    return {
      title: '时忆旅拍',
      path: '/pages/goods/category/index',
      promise
    }
  },
  //分享到朋友圈
  onShareTimeline() {},
});